package com.hsl.housaileibot001.ai.model;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import jakarta.annotation.Resource;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 通义千问聊天模型配置
 * 使用 OkHttp HTTP/2 客户端进行 API 请求
 * 
 * 禁用条件：设置 ai.provider=bailing 或 qwen.enabled=false
 */
// @Configuration
@ConditionalOnProperty(name = "qwen.enabled", havingValue = "true", matchIfMissing = false)
public class QwenChatModelConfig {

    @Value("${langchain4j.community.dashscope.chat-model.api-key}")
    private String apiKey;

    @Value("${langchain4j.community.dashscope.chat-model.model-name}")
    private String modelName;

    @Resource
    private ChatModelListener chatModelListener;

    @Bean("qwenChatModel2")
    public ChatModel qwenChatModel() {
        return QwenChatModel.builder()
                .apiKey(apiKey)
                .modelName(modelName)
                .listeners(List.of(chatModelListener))
                .maxTokens(1024)
                .temperature(0.7f)
                .topP(0.7)
                .enableSearch(true)
                .build();
    }
}